luci-app-attendedsysupgrade: avoid redirects, handle redirect errors
authorEric Fahlgren <[email protected]>
Thu, 29 May 2025 15:51:14 +0000 (08:51 -0700)
committerPaul Donald <[email protected]>
Sat, 7 Jun 2025 14:35:52 +0000 (17:35 +0300)
When users add an extraneous slash to the server url, then the ASU
server redirects GET requests.  But, this causes an error on POST
requests as the ASU server does not redirect those, so the LuCI
client failed inappropriately with an unhandled error.

Fix both of these by first trimming trailing slashes from the server
url as it is loaded to avoid the redirects.  Then, also handle all
unexpected responses, instead of just a select few.

Links: efahl/owut@724c990d6cc0
Signed-off-by: Eric Fahlgren <[email protected]>
applications/luci-app-attendedsysupgrade/htdocs/luci-static/resources/view/attendedsysupgrade/overview.js

index 148ef97e3ba635741dd9ba683fa22d9295869c34..579385d1581f186db78737a77b368683f0997c56 100644 (file)
@@ -338,19 +338,17 @@ return view.extend({
                                                        }
                                                }
                                                break;
-                                       case 400: // bad request
-                                       case 422: // bad package
-                                       case 500: // build failed
+                                       default:  // any error or unexpected responses
                                                if (main == true) {
                                                        poll.remove(this.pollFn);
                                                        this.handleError(response, data, firmware);
-                                                       break;
                                                } else {
                                                        poll.remove(this.rebuilder_polls[server]);
                                                        document.getElementById(server).innerText = '🚫 %s'.format(
                                                                server
                                                        );
                                                }
+                                               break;
                                }
                        });
        },
@@ -632,7 +630,7 @@ return view.extend({
                        uci.load('attendedsysupgrade'),
                ]);
                const data = {
-                       url: uci.get_first('attendedsysupgrade', 'server', 'url'),
+                       url: uci.get_first('attendedsysupgrade', 'server', 'url').replace(/\/+$/, ''),
                        branch: get_branch(promises[1].release.version),
                        revision: promises[1].release.revision,
                        efi: promises[2],